<html> <script language=javascript> setTimeout('window.location="../view/main.php"',500) </script> </html>
<?php 
header("Content-Type:text/html;charset=UTF-8");
require('../control/mysql.php');

 


$q1 = mysql_query("show tables");//把所有表的名字存在数组中
while ($t = mysql_fetch_array($q1)){
    $table = $t[0];
    $q2 = mysql_query("show create table `$table`");//获取表结构
    $sql = mysql_fetch_array($q2);
    $mysql= $sql['Create Table'] . ";\r\n";
    $q3 = mysql_query("select * from `$table`");
    while ($data = mysql_fetch_assoc($q3)){
        $keys = array_keys($data);
        $keys = array_map('addslashes', $keys);
        $keys = join('`,`', $keys);
        $keys = "`" . $keys . "`";
        $vals = array_values($data);
        $vals = array_map('addslashes', $vals);
        $vals = join("','", $vals);
        $vals = "'" . $vals . "'";
        $mysql .= "insert into `$table`($keys) values($vals);\r\n";
    } 
} 
 
$filename = $dbname . date('Ymjgi') . ".sql"; //存放路径，默认存放到项目最外层
$fp = fopen($filename, 'w');//w为写入方式打开
fputs($fp, $mysql);
fclose($fp);
echo "数据备份成功";
?>